package com.ruoyi.finish.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.finish.domain.FinishStudentInfo;
import com.ruoyi.train.domain.CertApplicationStudent;
import com.ruoyi.train.domain.StudentInformation;
import com.ruoyi.train.domain.StudentProcessRecord;
import com.ruoyi.train.service.ICertApplicationStudentService;
import com.ruoyi.train.service.IStudentInformationService;
import com.ruoyi.train.service.IStudentProcessRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.finish.service.IfinishStudentService;

import java.util.ArrayList;
import java.util.List;

/**
 * 学生完成审批信息Service业务层处理
 * 
 * @author wusihao
 * @date 2023-05-10
 */
@Service
public class finishStudentServiceImpl implements IfinishStudentService 
{

    @Autowired
    private IStudentInformationService studentInformationService;
    @Autowired
    private IStudentProcessRecordService studentProcessRecordService;
    @Autowired
    private ICertApplicationStudentService certApplicationStudentService;
    // 通过办证申请表id查询学生信息
    @Override
    public List<FinishStudentInfo> selectfinishStudentListBycertApplicationStudentId(Long certApplicationId) {
        // 存储答案集合
        List<FinishStudentInfo> finishStudentInfoList = new ArrayList<>();
        QueryWrapper<CertApplicationStudent> certApplicationStudentQueryWrapper = new QueryWrapper<>();
        certApplicationStudentQueryWrapper.eq("cert_application_id", certApplicationId);
        List<CertApplicationStudent> certApplicationStudentList = certApplicationStudentService.list(certApplicationStudentQueryWrapper);
        for (CertApplicationStudent certApplicationStudent : certApplicationStudentList) {
            FinishStudentInfo studentInfo = new FinishStudentInfo();
            Long studentId = certApplicationStudent.getStudentId();
            // 通过学生信息查找学生信息表，学生记录表
            QueryWrapper<StudentInformation> studentInformationQueryWrapper = new QueryWrapper<>();
            studentInformationQueryWrapper.eq("is_deleted", 0);
            studentInformationQueryWrapper.eq("id", studentId);
            StudentInformation studentInformationServiceOne = studentInformationService.getOne(studentInformationQueryWrapper);
            String serialNumber = studentInformationServiceOne.getSerialNumber();
            QueryWrapper<StudentProcessRecord> studentProcessRecordQueryWrapper = new QueryWrapper<>();
            studentProcessRecordQueryWrapper.eq("serial_number", serialNumber);
            studentInformationQueryWrapper.eq("exam_application_is_pass", 1);
            studentProcessRecordQueryWrapper.eq("exam_certificate_is_pass", 1);
            studentProcessRecordQueryWrapper.eq("cert_is_pass", 1);
            studentProcessRecordQueryWrapper.eq("is_deleted", 0);
            StudentProcessRecord studentProcessRecordServiceOne = studentProcessRecordService.getOne(studentProcessRecordQueryWrapper);
            if (studentProcessRecordServiceOne == null) continue;
            studentInfo.setUrlIdCopy(studentInformationServiceOne.getUrlIdCopy());
            studentInfo.setUrlPersonApplication(studentInformationServiceOne.getUrlPersonApplication());
            studentInfo.setUrlDegreeCertificate(studentInformationServiceOne.getUrlDegreeCertificate());
            studentInfo.setUrlHealthCertificate(studentInformationServiceOne.getUrlHealthCertificate());
            studentInfo.setName(studentInformationServiceOne.getName());
            studentInfo.setIdCard(studentInformationServiceOne.getIdCard());
            studentInfo.setPhone(studentInformationServiceOne.getPhone());
            studentInfo.setWorkplace(studentInformationServiceOne.getWorkplace());

            finishStudentInfoList.add(studentInfo);
        }
        return finishStudentInfoList;
    }
}
